/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author WinKiQue58
 */
@Entity
@Table(name = "WAREHOUSE")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Warehouse.findAll", query = "SELECT w FROM Warehouse w"),
    @NamedQuery(name = "Warehouse.findByIdWarehouse", query = "SELECT w FROM Warehouse w WHERE w.idWarehouse = :idWarehouse"),
    @NamedQuery(name = "Warehouse.findByName", query = "SELECT w FROM Warehouse w WHERE w.name = :name")})
public class Warehouse implements Serializable {
    private static final long serialVersionUID = 1L;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "ID_WAREHOUSE")
    private BigDecimal idWarehouse;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "NAME")
    private String name;
    @OneToMany(mappedBy = "warehouse", fetch = FetchType.LAZY)
    private List<Item> itemList;
    @JoinColumn(name = "ID_LOCATION", referencedColumnName = "ID_LOCATION")
    @ManyToOne(fetch = FetchType.LAZY)
    private Location idLocation;
    @JoinColumns({
        @JoinColumn(name = "ID_BRANCHENTERPRISE", referencedColumnName = "ID_BRANCHENTERPRISE"),
        @JoinColumn(name = "ID_ENTERPRISE", referencedColumnName = "ID_ENTERPRISE")})
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private BranchEnterprise branchEnterprise;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "warehouse", fetch = FetchType.LAZY)
    private List<Closure> closureList;

    public Warehouse() {
    }

    public Warehouse(BigDecimal idWarehouse) {
        this.idWarehouse = idWarehouse;
    }

    public Warehouse(BigDecimal idWarehouse, String name) {
        this.idWarehouse = idWarehouse;
        this.name = name;
    }

    public BigDecimal getIdWarehouse() {
        return idWarehouse;
    }

    public void setIdWarehouse(BigDecimal idWarehouse) {
        this.idWarehouse = idWarehouse;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlTransient
    public List<Item> getItemList() {
        return itemList;
    }

    public void setItemList(List<Item> itemList) {
        this.itemList = itemList;
    }

    public Location getIdLocation() {
        return idLocation;
    }

    public void setIdLocation(Location idLocation) {
        this.idLocation = idLocation;
    }

    public BranchEnterprise getBranchEnterprise() {
        return branchEnterprise;
    }

    public void setBranchEnterprise(BranchEnterprise branchEnterprise) {
        this.branchEnterprise = branchEnterprise;
    }

    @XmlTransient
    public List<Closure> getClosureList() {
        return closureList;
    }

    public void setClosureList(List<Closure> closureList) {
        this.closureList = closureList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idWarehouse != null ? idWarehouse.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Warehouse)) {
            return false;
        }
        Warehouse other = (Warehouse) object;
        if ((this.idWarehouse == null && other.idWarehouse != null) || (this.idWarehouse != null && !this.idWarehouse.equals(other.idWarehouse))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Warehouse[ idWarehouse=" + idWarehouse + " ]";
    }
    
}
